﻿using System.Configuration;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ReadyApps.Common;
using ReadyApps.Data;
using ReadyApps.Data.Oracle;
using ReadyAppsTest.Common;

namespace ReadyAppsTest.Data
{
    /// <summary>
    /// Summary description for WikiDataProviderFactoryTest
    /// </summary>
    [TestClass]
    public class WikiDataProviderFactoryTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        [TestMethod]
        [Description("Tests getting the test data provider")]
        public void GetInstanceTest()
        {
            TestAppSettings settings = new TestAppSettings();
            ReadyAppsSettings.SetAppSettings(settings);
            settings.WikiConnectionStringName = "name";
            settings.WikiDataProviderTypeName = typeof(TestWikiDataProvider).FullName;
            settings.WikiDataProviderAssembly = Assembly.GetExecutingAssembly().FullName;
            IWikiDataProvider dataProvider = WikiDataProviderFactory.GetInstance();
            Assert.IsInstanceOfType(dataProvider, typeof(TestWikiDataProvider));
            Assert.AreEqual(ConfigurationManager.ConnectionStrings["name"].ConnectionString,
                ((TestWikiDataProvider)dataProvider).ConnectionString);
        }

        [TestMethod]
        [Description("Tests creating an instance of the OracleWikiDataProvider with the assembly name")]
        public void GetInstanceOracleWithAssemblyTest()
        {
            TestAppSettings settings = new TestAppSettings();
            ReadyAppsSettings.SetAppSettings(settings);
            settings.WikiConnectionStringName = "name";
            settings.WikiDataProviderTypeName = typeof(OracleWikiDataProvider).FullName;
            settings.WikiDataProviderAssembly = typeof(OracleWikiDataProvider).Assembly.FullName;
            IWikiDataProvider dataProvider = WikiDataProviderFactory.GetInstance();
            Assert.IsInstanceOfType(dataProvider, typeof(OracleWikiDataProvider));
        }

        [TestMethod]
        [Description("Tests creating an instance of the OracleWikiDataProvider without the assembly name")]
        public void GetInstanceOracleWithoutAssemblyTest()
        {
            TestAppSettings settings = new TestAppSettings();
            ReadyAppsSettings.SetAppSettings(settings);
            settings.WikiConnectionStringName = "name";
            settings.WikiDataProviderTypeName = typeof(OracleWikiDataProvider).FullName;
            IWikiDataProvider dataProvider = WikiDataProviderFactory.GetInstance();
            Assert.IsInstanceOfType(dataProvider, typeof(OracleWikiDataProvider));
        }
    }
}
